package com.pylc.model.entity;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import javax.persistence.*;
import java.util.Set;

/**
 * 实体类 - 地区
 */

/**
 * @author Lindsey
 */
@Entity
@Table
public class Area extends BaseEntity {
    private static final long serialVersionUID = -2158109459123036967L;

    private String name;
    private int sortOrder;
    private int depth;
    private Area parent;
    private Set<Area> children;

    @Column(nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column
    public int getSortOrder() {
        return sortOrder;
    }

    public void setSortOrder(int sortOrder) {
        this.sortOrder = sortOrder;
    }

    @Column
    public int getDepth() {
        return depth;
    }

    public void setDepth(int depth) {
        this.depth = depth;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="parent_id", insertable=false, updatable=false)
    public Area getParent() {
        return parent;
    }

    public void setParent(Area parent) {
        this.parent = parent;
    }

    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name="parent_id")
    @Cascade(value = { CascadeType.DELETE })
    @OrderBy("sortOrder asc")
    public Set<Area> getChildren() {
        return children;
    }

    public void setChildren(Set<Area> children) {
        this.children = children;
    }
}